$(document).ready(function () {
    let corpId=$("#corpId").text();
    WeKnow.loading();
    //1.获取免登授权码code
    dd.runtime.permission.requestAuthCode({
        corpId: corpId, //企业id
        onSuccess: function (result) {
            var code = result.code;
            getUserInfo(code); //通过该code可以获取用户身份
        },
        onFail: function (err) {
            WeKnow.errorMsg('出错了, ' + err)
        }
    });
});

function getUserInfo(code) {
    $.ajax({
        type: "GET",
        url: "getDingTalkUserInfo?authCode=" + code,
        async: false,
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success: (function (res) {
            if (res.errCode == 1) {
                WeKnow.location("login");
            } else {
                WeKnow.errorMsg(res.errMsg)
            }
        }),
    });
}